package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.MenusMapper;
import com.gxa.p2p.pojo.Menus;
import com.gxa.p2p.service.MenuListService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author Longlin_Feng
 * @date 2020/8/6
 */
@Service
public class MenuListServiceImpl implements MenuListService {

  @Resource private MenusMapper menusMapper;

  @Override
  public List<Menus> getMenuList(Integer roleId) {

    System.out.println("roleId: " + roleId);
    // 一级菜单
    List<Menus> menus = menusMapper.selectByLevel(roleId, "0");

    if (menus.size() > 0) {
      for (Menus menu : menus) {
        // 查询二级菜单
        List<Menus> secondMenus = menusMapper.selectByLevel(roleId, menu.getMenuCode());
        if (secondMenus.size() > 0) {
          // 设置menu的subMenuList值为查到的子菜单对象
          menu.setSubMenusList(secondMenus);
        }
      }
    }
    return menus;
  }
}
